package com.hu.biz.service;

import org.springframework.stereotype.Service;

import java.util.Map;
import java.util.Set;
import java.util.concurrent.TimeUnit;

/**
 * @author 355760
 * @ClassName CacheService
 * @Description 缓存服务
 */
@Service
public interface ICacheService {

    boolean isValid(String key) throws Exception;

    String get(String key) throws Exception;

    <T> T getObj(String key, Class<T> obj) throws Exception;

    /**
     * 存储hashMap<String, String>
     *
     * @param name      mapName
     * @param key       mapKey
     * @param value     mapValue
     * @param expireSec 有效时长
     */
    void hmset(String name, String key, String value, Long expireSec) throws Exception;

    // 存储hashMap<String, Object>
    void hmset(String name, String key, Object value, Long expireSec) throws Exception;

    // 获取hashMap
    Object hmget(String name, String key) throws Exception;

    // 获取hashMap内key集合
    Set<Object> hkeys(String name) throws Exception;

    // 删除hashMap
    void hmdel(String name, Object... hashKeys) throws Exception;

    // 获取hashMap中的键值对
    Map<Object, Object> entries(String name) throws Exception;

    /**
     * 存储String, String
     *
     * @param key      key
     * @param value    value
     * @param expire   过期时间
     * @param timeUnit 时间类型 SECONDS MILLISECONDS etc.
     */
    void set(String key, String value, Long expire, TimeUnit timeUnit) throws Exception;

    // 存储String, String 无时间限制
    void set(String key, String value) throws Exception;

    // 存储String, Object
    void set(String key, Object value, Long expire, TimeUnit timeUnit) throws Exception;

    // 存储String, Object 无时间限制
    void set(String key, Object value) throws Exception;

    // 删除key
    void del(String key) throws Exception;

    // 存储List<String> 从左边插入
    void leftPush(String key, String value) throws Exception;
    // 删除和value相同的count个元素，

    /**
     * 删除和value相同的元素
     *
     * @param key   key
     * @param count count < 0，从右开始,count > 0，从左开始,count = 0，全部
     * @param value value
     */
    void remove(String key, Integer count, String value) throws Exception;

    /**
     * 存储set集合
     *
     * @param key   key
     * @param value value
     * @throws Exception 异常
     */
    void sAdd(String key, String value) throws Exception;

    /**
     * 获取指定key set集合
     *
     * @param key key
     * @return Set<String>
     */
    Set<String> members(String key);

    String setNxPx(String key, String value, Long ttl);

    void expire(String key, long ttl);

    void expire(String key, long ttl, TimeUnit unit);

    /**
     * 是否存在key
     *
     * @param key key
     * @return Boolean
     */
    Boolean hasKey(String key);
}
